<!--
// test 77: external SVG fonts, from Erik Dahlstrom
//
// SVGFonts are described here[3], and the relevant DOM methods
// used in the test are defined here[4].
//
// Note that in order to be more predictable the svg should be
// visible, so that clause "For non-rendering environments, the
// user agent shall make reasonable assumptions about glyph
// metrics." doesn't influence the results. We use 'opacity:0'
// to hide the SVG, but arguably it's still a "rendering
// environment".
//
// The font-size 4000 was chosen because that matches the
// unitsPerEm value in the svgfont, which makes it easy to check
// the glyph advances since they will then be exactly what was
// specified in the svgfont.
//
// [3] http://www.w3.org/TR/SVG11/fonts.html
// [4] http://www.w3.org/TR/SVG11/text.html#InterfaceSVGTextContentElement
-->

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../resources/js-test.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>
  description("Acid3 test 77, checking text metric functionality");

  window.jsTestIsAsync = true;
  if (window.testRunner)
    testRunner.waitUntilDone();

  var text;
  var iframe;

  function startTest() {
    iframe = document.createElement("iframe");
    iframe.onload = fontLoaded;
    iframe.src = "resources/Acid3Font-loader.svg";
    document.documentElement.appendChild(iframe);
  }

  var fontLoaded = function() {
    var svg = iframe.getSVGDocument().documentElement;
    text = iframe.getSVGDocument().getElementsByTagName('text')[0];
    text.textContent = "abc";
    text.setAttribute("y", "1em");
    text.setAttribute("font-size", "4000");
    executeTest();
  }

  function executeTest() {
    // The font-size 4000 was chosen because that matches the unitsPerEm value in the svgfont,
    // which makes it easy to check the glyph advances since they will then be exactly what was specified in the svgfont.
    shouldBe("text.getNumberOfChars()", "3");
    shouldBe("text.getComputedTextLength()", "4711+42+23");
    shouldBe("text.getSubStringLength(0,1)", "42");
    shouldBe("text.getSubStringLength(0,2)", "42+23");
    shouldBe("text.getSubStringLength(1,1)", "23");
    shouldBe("text.getSubStringLength(1,0)", "0");
    shouldBe("text.getSubStringLength(1, 3)", "4734");
    shouldBe("text.getSubStringLength(0, 4)", "4776");
    shouldThrow("text.getSubStringLength(3, 0)");
    shouldThrow("text.getSubStringLength(-17, 20)");
    shouldBe("text.getStartPositionOfChar(0).x", "0");
    shouldBe("text.getStartPositionOfChar(1).x", "42");
    shouldBe("text.getStartPositionOfChar(2).x", "42+23");
    shouldBe("text.getStartPositionOfChar(0).y", "4000");
    shouldThrow("text.getEndPositionOfChar(-1)");
    shouldThrow("text.getEndPositionOfChar(4)");
    shouldBe("text.getEndPositionOfChar(0).x", "42");
    shouldBe("text.getEndPositionOfChar(1).x", "42+23");
    shouldBe("text.getEndPositionOfChar(2).x", "42+23+4711");
    shouldThrow("text.getEndPositionOfChar(-17)");
    shouldThrow("text.getEndPositionOfChar(4)");

    finishJSTest();
  }

  startTest();
</script>
</body>
</html>
